package zhuyun.code.launcheractivity.view.adapter

import android.content.Context
import android.widget.TextView
import zhuyun.code.launcheractivity.R
import zhuyun.code.launcheractivity.model.data.CountryBean
import zhuyun.code.launcheractivity.model.data.FollowMainBean
import zhuyun.code.launcheractivity.model.data.interfaces.SelectTextItem

/**
 * @author: Administrator
 * @date: 2021/12/8
 */
class SelectTextListAdapter(val context: Context, data:MutableList<SelectTextItem>):
    BaseQuickAdapter<SelectTextItem,BaseViewHolder>(R.layout.item_select_text,data) {
    var selectedItemId:Int? = null
    var onItemClickListener:OnItemClickListener? = null
    var lastSelectedItem:SelectTextItem? = null


    override fun convert(helper: BaseViewHolder, item: SelectTextItem) {
        val textView = helper.getView<TextView>(R.id.text)
        if(item is CountryBean){
            textView.text = item.CountryName
            selectedItemId?.let {
                textView.isEnabled = item.CountryId != it
            }
        } else if(item is FollowMainBean){
            textView.text = item.MainClassName
            selectedItemId?.let {
                textView.isEnabled =item.MainClassId != it
            }
        }
        helper.itemView.setOnClickListener{
            if(item!=lastSelectedItem){
                onItemClickListener?.onItemClick(item)
                lastSelectedItem = item
            }

        }

    }
    interface OnItemClickListener{
        fun onItemClick(item:SelectTextItem)
    }

}